
#ifndef _BROWSER_H_
#define _BROWSER_H_

#include <QApplication>
#include <QDebug>
#include <QList>
#include <QPointer>
#include <QVariantMap>
#include <QVariant>
#include "webpage.h"
//#include "cookiejar.h"
#include "setting.h"
#include "webpageadapter.h"

#define MAX_BROWSER_PAGE 50

class Browser: public QObject {
    Q_OBJECT
    private:
        Browser(QObject *parent = 0);
        void init();

    public:
        virtual ~Browser();
        static Browser *instance();

        // We can't prevate other to use webpage when webpage be destory, so be careful.
        // User absolutely impossible to delete WebPageAdapter by them self !
        // mey be we can code a smart pointer to solve it.
        WebPageAdapter *createWebPage(PageProtocol *client, WebSpiderRequest *req);
        Operator* appendWebPage(WebPage *page);
        bool destoryWebPage(WebPageAdapter *page);

        QVariantMap& defaultPageSettings();

    private Q_SLOTS:
        void onInitialized();

    private:
        QList<WebPage* > m_pages;
        QList<WebPage* > m_freePages;
        Setting::PageSetting *m_defaultPageSettings;
        static Browser* m_browser;
};

#endif

